package com.itheima.tcp;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketDemoFour02 {
    public static void main(String[] args) throws IOException {
        //1.创建ServerSocket对象
        ServerSocket sc=new ServerSocket(8080);
       // System.out.println(111);
        //2.监听客户端连接，返回一个Socker对象
        Socket accept=sc.accept();
       // System.out.println(333);
        //3.获取输入流，读数据，显示在控制台
        InputStream inputStream = accept.getInputStream();
        int b;
        while ((b=inputStream.read())!=-1){
            System.out.println((char)b);
        }
//        OutputStream ou = accept.getOutputStream();
//        ou.write("你谁啊？".getBytes());//有中文，乱码，要用转换流
//        ou.close();
        BufferedWriter bu=new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bu.write("你谁啊");
        bu.close();
        sc.close();
        accept.close();
        //4.释放
    }
}
